#递归函数
#计算阶乘
def fact(n):
    if n == 1:
        return 1
    return n * fact(n-1)
print(fact(1))
print(fact(5))
print(fact(100))
#print(fact(1000)) #递归次数过多会导致栈溢出

#尾递归
def fact2(n):
    return fact_iter(n,1)
    
def fact_iter(n,product):
    if n==1:
        return product
    return fact_iter(n-1, n * product)
    
print(fact2(1))
print(fact2(5))
print(fact2(10))
print(fact2(100))
#print(fact2(1000))